package com.github.zyflzz.mycalculator;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import com.github.zyflzz.mycalculator.core.Calculator;
import com.github.zyflzz.mycalculator.recyclerview.Record;
import com.github.zyflzz.mycalculator.recyclerview.RecyclerViewAdapter;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class HistoryActivity extends AppCompatActivity {

    private final Calculator calculator = Calculator.getCalculator();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_history);

        RecyclerView recyclerView = findViewById(R.id.recycler);
        Stack<Record> recordStack = (Stack<Record>) calculator.getHistoryStack().clone();
        List<Record> recordList = new ArrayList<>();
        while (!recordStack.empty()) {
            recordList.add(recordStack.pop());
        }

        RecyclerViewAdapter adapter = new RecyclerViewAdapter(this, recordList);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);

        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(linearLayoutManager);
    }
}